//
//  Trough.m
//  SKPAD
//
//  Created by admin@amonline.com.cn on 15/5/4.
//  Copyright (c) 2015年 amo. All rights reserved.
//

#import "VerticalThreeToneTrough.h"

@implementation VerticalThreeToneTrough

-(id) init
{
    self = [super init];
    if (self) {
        _trackLayerTrough = [CAShapeLayer layer];
        _trackLayerTrough.strokeColor = [UIColor lightGrayColor].CGColor;
        _trackLayerTrough.fillColor = [UIColor clearColor].CGColor;
        _trackLayerTrough.lineCap = kCALineCapRound;
        _trackLayerTrough.lineWidth = 2.0f;
        
        _trackLayerblackTrough = [CAShapeLayer layer];
        _trackLayerblackTrough.strokeColor = [UIColor lightGrayColor].CGColor;
        _trackLayerblackTrough.fillColor = [UIColor blackColor].CGColor;
        _trackLayerblackTrough.lineCap = kCALineCapRound;
        _trackLayerblackTrough.lineWidth = 2.0f;
    }
    return self;
}

-(void) updateTrackLayerTrough
{
    UIBezierPath *pointer = [UIBezierPath bezierPath];
    pointer.lineJoinStyle = kCGLineCapRound; //终点处理
    
    CGFloat hx = fabs(_trackLayerTrough.bounds.size.width - _trackLayerTrough.bounds.origin.x)/2;
    CGFloat sx = fabs(_trackLayerTrough.bounds.size.height - _trackLayerTrough.bounds.origin.y)/20;
    
    CGRect valueRect;
    valueRect.origin.x = _trackLayerTrough.bounds.origin.x + hx;
    valueRect.origin.y = _trackLayerTrough.bounds.origin.y + sx;
    valueRect.size.width = hx * 2;
    valueRect.size.height = sx * 18;
    pointer = [UIBezierPath bezierPathWithRoundedRect:valueRect cornerRadius:_trackLayerTrough.bounds.size.width / 2];
    self.trackLayerTrough.path = pointer.CGPath;
    self.trackLayerblackTrough.path = pointer.CGPath;
}

-(void) setLineWidth:(CGFloat)lineWidth
{
    if(lineWidth != _lineWidth)
    {
        _lineWidth = lineWidth;
        _trackLayerTrough.lineWidth = _lineWidth;
        [self updateTrackLayerTrough];
    }
}

-(void) setBColor:(UIColor *)bColor
{
    if(bColor != _bColor)
    {
        _bColor = bColor;
        _trackLayerblackTrough.fillColor = _bColor.CGColor;
        [self updateTrackLayerTrough];
    }
}

-(void) setLColor:(UIColor *)lColor
{
    if(lColor != _lColor)
    {
        _lColor = lColor;
        _trackLayerTrough.strokeColor = _lColor.CGColor;
        _trackLayerblackTrough.strokeColor = _lColor.CGColor;
        [self updateTrackLayerTrough];
    }
}

-(void)updateWithBounds:(CGRect)bounds
{
    //设置图层位置大小
    self.trackLayerTrough.bounds = bounds;
    self.trackLayerTrough.position = CGPointMake(CGRectGetWidth(bounds)/2.0, CGRectGetHeight(bounds)/2.0);
    self.trackLayerblackTrough.bounds = bounds;
    self.trackLayerblackTrough.position = CGPointMake(CGRectGetWidth(bounds)/2.0, CGRectGetHeight(bounds)/2.0);
    [self updateTrackLayerTrough];
}

@end